$(function () {
    // alert(11)
    //alert(11)
    $('.address').on('click', function () {
        location.href = './address.html'
    })
    $('.order').on('click', function () {
        location.href = '/history-order.html'
    })
    $('.quitLogin').on('click', function () {
        location.href = './login.html'
    })

    $('.icon-arrow-left').on('click', function () {
        location.href = './index.html'
    })
    //最新订单
    getOrder()
    //过滤器 计算总数
    template.defaults.imports.sum = function (val) {
        let Sum = 0
        val.forEach(val => {
            Sum += val.number
        })
        return Sum
    }
    //配送状态
    template.defaults.imports.dateFormat = function (val) {
        if (val === 2) {
            return '正在派送'
        } else if (val === 3) {
            return '已派送'
        } else if (val === 4) {
            return '已完成'
        }
    }

    function getOrder() {
        $.ajax({
            method: 'get',
            url: 'http://121.4.102.44:8083/order/userPage?page=1&pageSize=1',
            data: {

            },
            success(res) {
                console.log(res);
                if (res.code !== 1) {
                    return layui.layer.msg(res.msg, { icon: 5 })
                }
                const htmlStr = template('hlq_tpl', res.data)
                $('.divOrders').html(htmlStr)
            }


        })
    }
})